package ioProcessor;

import io.CommandIO;
import io.TimeTableOutput;

import java.io.IOException;
import java.util.ArrayList;

import entities.Room;
import entities.Section;
import entities.Staff;

public class OutputProcessor {
	public static void process() {
		String[] allSections = Section.getSectionIdList();
		for (String section : allSections) {
			String output = Section.getSectionById(section).toString();
			try {
				TimeTableOutput.outputTimetable(output + "\n");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public static void processStaffSchedule(String cmd) {
		String[] cmds = cmd.split(" ");
		if (cmds.length != 1) {
			System.out.println("Invalid command format.\n");
			return;
		}
		Staff staff = Staff.getStaffById(cmds[0]);
		if (staff == null) {
			System.out.println("Invalid staff ID.\n");
			return;
		}
		ArrayList<String> sectionIds = staff.getAllSectionIds();
		String output = "";
		for (String sectionId : sectionIds) {
			output += Section.getSectionById(sectionId).toString() + "\n";
		}
		CommandIO.output(output);
	}

	public static void processRoomSchedule(String cmd) {
		String[] cmds = cmd.split(" ");
		if (cmds.length != 1) {
			System.out.println("Invalid command format.\n");
			return;
		}
		Room room = Room.getRoomById(cmds[0]);
		if (room == null) {
			System.out.println("Invalid room ID.\n");
			return;
		}
		String[] sectionIds = room.getRelatedSectionIds();
		String output = "";
		for (String sectionId : sectionIds) {
			output += Section.getSectionById(sectionId).toString() + "\n";
		}
		CommandIO.output(output);
	}
}
